/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package practicadwh;


import basedatos.Conexion;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import javax.swing.UIManager.*;
import javax.swing.table.DefaultTableModel;
import jerarquia.JPanel_imagen;
import jerarquia.grafica;
import jerarquia.nodo_arbol;

/**
 *
 * @author yojugracu
 */
public class Principal extends javax.swing.JFrame implements Runnable {

    /**
     * Creates new form Principal
     */
    
    private String tabla_hecho;
    public LinkedList <nodo_arbol> lista_jerarquia; //testa es la estructura que maneja las tablas y las jerarquias
    private DefaultListModel modelo_dimenciones=new DefaultListModel();
    private DefaultListModel modelo_dim_reales=new DefaultListModel();
    private DefaultListModel modelo_campos=new DefaultListModel();
    private DefaultListModel modelo_campos_reales=new DefaultListModel();
    private DefaultListModel modelo1=new DefaultListModel();
    private DefaultListModel modelo_campo_fecha=new DefaultListModel();
    public nodo_arbol dimencion_actual;
    public nodo_arbol dimencion_mov;
    private boolean calculado;
    public ArrayList<String> campos_tblHecho;
    public ArrayList<String> campos_tblHecho2;
    private LinkedList<String> restriccion_llave;
    private String restriccion_campo;
    
    public Principal() {
        try {
            JFrame.setDefaultLookAndFeelDecorated( true );
            JDialog.setDefaultLookAndFeelDecorated( true );
           // UIManager.setLookAndFeel( new com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel() );
            UIManager.setLookAndFeel( new com.nilo.plaf.nimrod.NimRODLookAndFeel() );
            //UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }catch( Exception e ){ e.printStackTrace(); }
        initComponents();
        accPrincipal = new AccionesPrincipal( this );
        jList1.setModel(modelo_dimenciones);
        jList3.setModel(modelo_dim_reales);
        jList2.setModel(modelo_campos);
        jList4.setModel(modelo_campos_reales);
        jList5.setModel(modelo1);
        jList6.setModel(modelo_campo_fecha);
        jPanel4.setVisible(false);
        this.setLocationRelativeTo(null);
        calculado=false;
        restriccion_llave=new LinkedList<String>();
        campos_tblHecho=new ArrayList<String>();
        campos_tblHecho2=new ArrayList<String>();
        propiedades = new Propiedades();
        tabla_hecho=null;
        restriccion_campo="";
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jdConexion = new javax.swing.JDialog();
        jLabel3 = new javax.swing.JLabel();
        txtUsuario = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtNombreBD = new javax.swing.JTextField();
        btnConectar = new javax.swing.JButton();
        btnCancelarCon = new javax.swing.JButton();
        txtPassword = new javax.swing.JPasswordField();
        jdCampos_calculados = new javax.swing.JDialog();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList5 = new javax.swing.JList();
        jPanel4 = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jLabel14 = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        txt_definicion = new javax.swing.JTextArea();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jdProyecto = new javax.swing.JDialog();
        jTabbedPane2 = new javax.swing.JTabbedPane();
        jPanel6 = new javax.swing.JPanel();
        jLabel27 = new javax.swing.JLabel();
        txtNProyecto = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        txtUProyecto = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        txtUBackUP = new javax.swing.JTextField();
        btnUProyecto = new javax.swing.JButton();
        btnUBackUp = new javax.swing.JButton();
        jPanel7 = new javax.swing.JPanel();
        jLabel19 = new javax.swing.JLabel();
        txtUsuario1 = new javax.swing.JTextField();
        jLabel20 = new javax.swing.JLabel();
        txtPassword1 = new javax.swing.JPasswordField();
        jLabel21 = new javax.swing.JLabel();
        txtNombreBD1 = new javax.swing.JTextField();
        jLabel22 = new javax.swing.JLabel();
        jLabel23 = new javax.swing.JLabel();
        txtServidor = new javax.swing.JTextField();
        txtPuerto = new javax.swing.JTextField();
        jPanel8 = new javax.swing.JPanel();
        btnCrearProyecto = new javax.swing.JButton();
        btnCancelarP = new javax.swing.JButton();
        jdProgreso = new javax.swing.JDialog();
        jpbProgreso = new javax.swing.JProgressBar();
        lblMensajeProgreso = new javax.swing.JLabel();
        grupo_funciones = new javax.swing.ButtonGroup();
        jSplitPane1 = new javax.swing.JSplitPane();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtProyecto = new javax.swing.JTree();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel3 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cboTablaHechos = new javax.swing.JComboBox();
        jspTablaHecho = new javax.swing.JScrollPane();
        jtDatosTabla = new javax.swing.JTable();
        btnAdd = new javax.swing.JButton();
        btnRemove = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtMetricas = new javax.swing.JTable();
        jLabel6 = new javax.swing.JLabel();
        jButton10 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        cmb_dimenciones = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        jLabel11 = new javax.swing.JLabel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jList2 = new javax.swing.JList();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jScrollPane5 = new javax.swing.JScrollPane();
        jList3 = new javax.swing.JList();
        jScrollPane6 = new javax.swing.JScrollPane();
        jList4 = new javax.swing.JList();
        jSeparator1 = new javax.swing.JSeparator();
        jLabel15 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        jLabel17 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel18 = new javax.swing.JLabel();
        jScrollPane10 = new javax.swing.JScrollPane();
        jList6 = new javax.swing.JList();
        jPanel5 = new javax.swing.JPanel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jCheckBox5 = new javax.swing.JCheckBox();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jButton16 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jScrollPane7 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton15 = new javax.swing.JButton();
        jPanel9 = new javax.swing.JPanel();
        jScrollPane11 = new javax.swing.JScrollPane();
        jTextArea2 = new javax.swing.JTextArea();
        jButton17 = new javax.swing.JButton();
        jButton18 = new javax.swing.JButton();
        jPanel11 = new javax.swing.JPanel();
        jScrollPane12 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        cbo_movMetricas = new javax.swing.JComboBox();
        jLabel24 = new javax.swing.JLabel();
        jButton21 = new javax.swing.JButton();
        jPanel13 = new javax.swing.JPanel();
        jLabel26 = new javax.swing.JLabel();
        cbo_movNivel = new javax.swing.JComboBox();
        cbo_movDimenciones = new javax.swing.JComboBox();
        jLabel25 = new javax.swing.JLabel();
        jPanel14 = new javax.swing.JPanel();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        cbo_movDimenciones2 = new javax.swing.JComboBox();
        cbo_movNivel2 = new javax.swing.JComboBox();
        jScrollPane15 = new javax.swing.JScrollPane();
        jTextArea4 = new javax.swing.JTextArea();
        jButton20 = new javax.swing.JButton();
        rd_sumar = new javax.swing.JRadioButton();
        rd_promedio = new javax.swing.JRadioButton();
        jPanel15 = new javax.swing.JPanel();
        jLabel32 = new javax.swing.JLabel();
        jLabel33 = new javax.swing.JLabel();
        cbo_restriccion = new javax.swing.JComboBox();
        cbo_campo_restriccion = new javax.swing.JComboBox();
        cbo_operador = new javax.swing.JComboBox();
        jLabel34 = new javax.swing.JLabel();
        jLabel35 = new javax.swing.JLabel();
        txt_val_condicion = new javax.swing.JTextField();
        jButton23 = new javax.swing.JButton();
        jButton24 = new javax.swing.JButton();
        jToolBar1 = new javax.swing.JToolBar();
        btnNuevo = new javax.swing.JButton();
        btnAbrir = new javax.swing.JButton();
        jButton19 = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        mnuArchivo = new javax.swing.JMenu();
        mnuNuevo = new javax.swing.JMenuItem();
        mnuAbrir = new javax.swing.JMenuItem();
        mnuGuardar = new javax.swing.JMenuItem();
        mnuSalir = new javax.swing.JMenuItem();
        mnuEditar = new javax.swing.JMenu();
        mnuConectar = new javax.swing.JMenuItem();
        mnuAyuda = new javax.swing.JMenu();
        mnuAcercaDe = new javax.swing.JMenuItem();

        jdConexion.setTitle("Conectar con...");

        jLabel3.setText("Usuario");

        txtUsuario.setText("postgres");
        txtUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUsuarioActionPerformed(evt);
            }
        });

        jLabel4.setText("Password");

        jLabel5.setText("Nombre BD");

        txtNombreBD.setText("prueba");

        btnConectar.setText("Conectar");
        btnConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnConectarActionPerformed(evt);
            }
        });

        btnCancelarCon.setText("Cancelar");
        btnCancelarCon.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarConActionPerformed(evt);
            }
        });

        txtPassword.setText("yojugracu");

        javax.swing.GroupLayout jdConexionLayout = new javax.swing.GroupLayout(jdConexion.getContentPane());
        jdConexion.getContentPane().setLayout(jdConexionLayout);
        jdConexionLayout.setHorizontalGroup(
            jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdConexionLayout.createSequentialGroup()
                .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jdConexionLayout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addComponent(btnConectar)
                        .addGap(34, 34, 34)
                        .addComponent(btnCancelarCon))
                    .addGroup(jdConexionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addComponent(jLabel4))
                        .addGap(18, 18, 18)
                        .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNombreBD, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtUsuario, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jdConexionLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel3)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jdConexionLayout.setVerticalGroup(
            jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdConexionLayout.createSequentialGroup()
                .addGap(0, 31, Short.MAX_VALUE)
                .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtUsuario, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(txtNombreBD, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jdConexionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnConectar)
                    .addComponent(btnCancelarCon))
                .addGap(26, 26, 26))
        );

        jdCampos_calculados.setTitle("Campos calculados");
        jdCampos_calculados.setIconImage(null);

        jLabel2.setText("Metricas seleccionadas:");

        jList5.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane8.setViewportView(jList5);

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Nuevo campo calculado"));

        jLabel12.setText("Nombre del campo:");

        jLabel13.setText("Tipo:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "integer", "real" }));

        jLabel14.setText("Defiinicion del campo:");

        txt_definicion.setColumns(20);
        txt_definicion.setRows(5);
        jScrollPane9.setViewportView(txt_definicion);

        jButton8.setText("Aceptar");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setText("Cancelar");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane9)
                            .addGroup(jPanel4Layout.createSequentialGroup()
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addComponent(jLabel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jLabel13))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton9)))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel13)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(30, 30, 30)
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton8)
                    .addComponent(jButton9))
                .addContainerGap())
        );

        jButton5.setText("Agregar campo");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("Copy to Clipboard");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton11.setText("Finalizar");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jdCampos_calculadosLayout = new javax.swing.GroupLayout(jdCampos_calculados.getContentPane());
        jdCampos_calculados.getContentPane().setLayout(jdCampos_calculadosLayout);
        jdCampos_calculadosLayout.setHorizontalGroup(
            jdCampos_calculadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCampos_calculadosLayout.createSequentialGroup()
                .addGap(21, 21, 21)
                .addGroup(jdCampos_calculadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 199, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addGroup(jdCampos_calculadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jButton11))
                .addGap(18, 18, 18)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jdCampos_calculadosLayout.setVerticalGroup(
            jdCampos_calculadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdCampos_calculadosLayout.createSequentialGroup()
                .addGap(26, 26, 26)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton5)
                .addGap(18, 18, 18)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 41, Short.MAX_VALUE)
                .addComponent(jButton11)
                .addGap(21, 21, 21))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jdCampos_calculadosLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        jdProyecto.setTitle("Crear Proyecto");

        jLabel27.setText("Nombre del Proyecto:");

        jLabel28.setText("Ubicacion del Proyecto");

        txtUProyecto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUProyectoActionPerformed(evt);
            }
        });

        jLabel29.setText("Ubicacion del backup");

        txtUBackUP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUBackUPActionPerformed(evt);
            }
        });

        btnUProyecto.setText("...");
        btnUProyecto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUProyectoActionPerformed(evt);
            }
        });

        btnUBackUp.setText("...");
        btnUBackUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnUBackUpActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel28)
                    .addComponent(jLabel27)
                    .addComponent(jLabel29))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txtNProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtUBackUP, javax.swing.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE)
                    .addComponent(txtUProyecto))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnUProyecto)
                    .addComponent(btnUBackUp))
                .addContainerGap(32, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addGap(34, 34, 34)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel27)
                    .addComponent(txtNProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel28)
                    .addComponent(txtUProyecto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnUProyecto))
                .addGap(18, 18, 18)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel29)
                    .addComponent(txtUBackUP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnUBackUp))
                .addContainerGap(136, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab("Nuevo Proyecto", jPanel6);

        jLabel19.setText("Usuario");

        txtUsuario1.setText("postgres");
        txtUsuario1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtUsuario1ActionPerformed(evt);
            }
        });

        jLabel20.setText("Password");

        txtPassword1.setText("yojugracu");

        jLabel21.setText("Nombre BD");

        txtNombreBD1.setText("prueba");

        jLabel22.setText("Servidor");

        jLabel23.setText("Puerto");

        txtServidor.setText("localhost");

        txtPuerto.setText("5432");

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel21)
                            .addComponent(jLabel20)
                            .addComponent(jLabel23))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(txtPassword1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(txtNombreBD1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(txtUsuario1, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                            .addComponent(txtServidor)
                            .addComponent(txtPuerto)))
                    .addComponent(jLabel22))
                .addContainerGap(183, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel19, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txtUsuario1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtPassword1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel20))
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel21)
                    .addComponent(txtNombreBD1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel22)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(txtServidor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtPuerto, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel23))))
                .addContainerGap(57, Short.MAX_VALUE))
        );

        jTabbedPane2.addTab("Conexion Proyecto", jPanel7);

        jdProyecto.getContentPane().add(jTabbedPane2, java.awt.BorderLayout.CENTER);

        btnCrearProyecto.setText("Crear");
        btnCrearProyecto.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCrearProyectoActionPerformed(evt);
            }
        });
        jPanel8.add(btnCrearProyecto);

        btnCancelarP.setText("Cancelar");
        btnCancelarP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarPActionPerformed(evt);
            }
        });
        jPanel8.add(btnCancelarP);

        jdProyecto.getContentPane().add(jPanel8, java.awt.BorderLayout.SOUTH);

        jdProgreso.setTitle("Ejecutando...");

        jpbProgreso.setStringPainted(true);

        lblMensajeProgreso.setText("...");

        javax.swing.GroupLayout jdProgresoLayout = new javax.swing.GroupLayout(jdProgreso.getContentPane());
        jdProgreso.getContentPane().setLayout(jdProgresoLayout);
        jdProgresoLayout.setHorizontalGroup(
            jdProgresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdProgresoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jdProgresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jpbProgreso, javax.swing.GroupLayout.DEFAULT_SIZE, 268, Short.MAX_VALUE)
                    .addComponent(lblMensajeProgreso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jdProgresoLayout.setVerticalGroup(
            jdProgresoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jdProgresoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblMensajeProgreso)
                .addGap(8, 8, 8)
                .addComponent(jpbProgreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Proyecto");
        jtProyecto.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane2.setViewportView(jtProyecto);

        jSplitPane1.setLeftComponent(jScrollPane2);

        jTabbedPane1.setTabLayoutPolicy(javax.swing.JTabbedPane.SCROLL_TAB_LAYOUT);
        jTabbedPane1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jPanel3.setLayout(null);

        jLabel1.setText("Seleccionar Tabla Hecho:");
        jPanel3.add(jLabel1);
        jLabel1.setBounds(10, 20, 160, 14);

        cboTablaHechos.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                cboTablaHechosMouseClicked(evt);
            }
        });
        cboTablaHechos.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cboTablaHechosPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });
        cboTablaHechos.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                cboTablaHechosItemStateChanged(evt);
            }
        });
        cboTablaHechos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cboTablaHechosActionPerformed(evt);
            }
        });
        jPanel3.add(cboTablaHechos);
        cboTablaHechos.setBounds(177, 20, 190, 20);

        jtDatosTabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null},
                {null, null, null},
                {null, null, null},
                {null, null, null}
            },
            new String [] {
                "Llave", "Nombre", "Tipo"
            }
        ));
        jspTablaHecho.setViewportView(jtDatosTabla);

        jPanel3.add(jspTablaHecho);
        jspTablaHecho.setBounds(34, 100, 390, 286);

        btnAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/plus.png"))); // NOI18N
        btnAdd.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAddActionPerformed(evt);
            }
        });
        jPanel3.add(btnAdd);
        btnAdd.setBounds(440, 180, 33, 33);

        btnRemove.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/minus.png"))); // NOI18N
        btnRemove.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        btnRemove.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnRemoveActionPerformed(evt);
            }
        });
        jPanel3.add(btnRemove);
        btnRemove.setBounds(440, 230, 29, 32);

        jtMetricas.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Llave", "Nombre", "Tipo", "Otro"
            }
        ));
        jScrollPane1.setViewportView(jtMetricas);

        jPanel3.add(jScrollPane1);
        jScrollPane1.setBounds(490, 100, 410, 290);

        jLabel6.setText("Seleccionar Metricas");
        jPanel3.add(jLabel6);
        jLabel6.setBounds(10, 60, 130, 14);

        jButton10.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/ok.gif"))); // NOI18N
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton10);
        jButton10.setBounds(380, 10, 40, 40);

        jButton12.setText("+/*");
        jButton12.setToolTipText("Agregue campos calculados a partir de las metricas seleccionadas");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton12);
        jButton12.setBounds(430, 270, 51, 23);

        jTabbedPane1.addTab("Tabla de Hecho", new javax.swing.ImageIcon(getClass().getResource("/imagenes/data_table.png")), jPanel3); // NOI18N

        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jList1MouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(jList1);

        jLabel7.setText("Tabla de Hecho:");

        jLabel9.setText("Dimenciones:");

        cmb_dimenciones.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cmb_dimencionesPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        jLabel10.setText("Jerarquia dimencion");

        jLabel11.setText("Campos");

        jScrollPane4.setViewportView(jList2);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/aderechaa.png"))); // NOI18N
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/aizquierdaa.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/aderechaa.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton7.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/aizquierdaa.png"))); // NOI18N
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jScrollPane5.setViewportView(jList3);

        jScrollPane6.setViewportView(jList4);

        jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL);

        jLabel15.setText("Dimencion de tiempo");

        jLabel16.setText("<html>Seleccione la tabla que contiene el campo para <br> generar la dimención de tiempo</html>");

        jLabel17.setText("Tabla:");

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox2.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                jComboBox2PopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        jLabel18.setText("Campo:");

        jList6.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane10.setViewportView(jList6);

        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Nivel de detalle"));

        jCheckBox1.setText("Año");

        jCheckBox2.setText("Semestre");

        jCheckBox3.setText("Trimestre");

        jCheckBox4.setText("Mes");

        jCheckBox5.setText("Día");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBox3)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox1)
                            .addComponent(jCheckBox2))
                        .addGap(11, 11, 11)
                        .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jCheckBox5)
                            .addComponent(jCheckBox4))))
                .addContainerGap(17, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox1)
                    .addComponent(jCheckBox4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCheckBox2)
                    .addComponent(jCheckBox5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBox3)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jButton13.setText("Establecer");
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.setText("Cancelar");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(18, 18, 18)
                        .addComponent(cmb_dimenciones, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel10)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel11)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                                            .addComponent(jScrollPane4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jButton3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                            .addComponent(jButton7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                        .addGap(18, 18, 18)
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 162, Short.MAX_VALUE)
                                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))))))
                        .addGap(40, 40, 40)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel16, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel15)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jLabel17)
                                        .addGap(18, 18, 18)
                                        .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                            .addComponent(jLabel18)
                                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                            .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 134, javax.swing.GroupLayout.PREFERRED_SIZE))))
                                .addGap(0, 0, Short.MAX_VALUE)))
                        .addGap(41, 41, 41)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(56, 56, 56))))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel9)
                            .addComponent(cmb_dimenciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel7))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(33, 33, 33)
                                .addComponent(jButton3)
                                .addGap(26, 26, 26)
                                .addComponent(jButton4))
                            .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 163, Short.MAX_VALUE)
                            .addComponent(jScrollPane3))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel11)
                        .addGap(18, 18, 18)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addComponent(jButton2)
                                .addGap(18, 18, 18)
                                .addComponent(jButton7)
                                .addGap(50, 50, 50))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 178, Short.MAX_VALUE)
                                    .addComponent(jScrollPane6))
                                .addGap(32, 32, 32))))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(jSeparator1)
                                .addGap(23, 23, 23))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(25, 25, 25)
                                .addComponent(jLabel15)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(jLabel17)
                                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(jButton13)
                                        .addGap(18, 18, 18)
                                        .addComponent(jButton14))
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addComponent(jLabel18)
                                            .addComponent(jScrollPane10, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addGap(40, 107, Short.MAX_VALUE))))))
        );

        jTabbedPane1.addTab("Opciones", new javax.swing.ImageIcon(getClass().getResource("/imagenes/table_edit.png")), jPanel1); // NOI18N

        jButton16.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/script_palette.png"))); // NOI18N
        jButton16.setText("Graficar");
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jButton16)
                .addContainerGap(970, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(jButton16)
                .addContainerGap(420, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Grafico dimencional", new javax.swing.ImageIcon(getClass().getResource("/imagenes/table_relationship.png")), jPanel10); // NOI18N

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/script_code.png"))); // NOI18N
        jButton1.setText("Generar Script");
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane7.setViewportView(jTextArea1);

        jButton15.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/script_gear.png"))); // NOI18N
        jButton15.setText("Ejecutar Script");
        jButton15.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton15.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jButton1)
                    .addComponent(jButton15))
                .addGap(91, 91, 91)
                .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 683, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(200, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addComponent(jButton1)
                        .addGap(18, 18, 18)
                        .addComponent(jButton15)
                        .addGap(0, 312, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Modelo dimencional", new javax.swing.ImageIcon(getClass().getResource("/imagenes/table_gear.png")), jPanel2); // NOI18N

        jTextArea2.setColumns(20);
        jTextArea2.setRows(5);
        jScrollPane11.setViewportView(jTextArea2);

        jButton17.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/script_code.png"))); // NOI18N
        jButton17.setText("Generar Scrip de datos");
        jButton17.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton17.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });

        jButton18.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/script_gear.png"))); // NOI18N
        jButton18.setText("Ejecutar Script");
        jButton18.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton18.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton18.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton18ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton18, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(62, 62, 62)
                .addComponent(jScrollPane11, javax.swing.GroupLayout.PREFERRED_SIZE, 700, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(185, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel9Layout.createSequentialGroup()
                        .addGap(34, 34, 34)
                        .addComponent(jButton17)
                        .addGap(18, 18, 18)
                        .addComponent(jButton18)
                        .addGap(0, 311, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel9Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Proceso ETL", new javax.swing.ImageIcon(getClass().getResource("/imagenes/batch_process.png")), jPanel9); // NOI18N

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4", "null", "Title 6", "Title 7"
            }
        ));
        jScrollPane12.setViewportView(jTable1);

        jLabel24.setText("Metricas");

        jButton21.setText("Generar consulta");
        jButton21.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton21ActionPerformed(evt);
            }
        });

        jPanel13.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dimención 1\n"));

        jLabel26.setText("Campo:");

        cbo_movNivel.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--" }));
        cbo_movNivel.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbo_movNivelPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        cbo_movDimenciones.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--" }));
        cbo_movDimenciones.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbo_movDimencionesPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });
        cbo_movDimenciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbo_movDimencionesActionPerformed(evt);
            }
        });

        jLabel25.setText("Dimención");

        javax.swing.GroupLayout jPanel13Layout = new javax.swing.GroupLayout(jPanel13);
        jPanel13.setLayout(jPanel13Layout);
        jPanel13Layout.setHorizontalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel25)
                    .addComponent(jLabel26))
                .addGap(18, 18, 18)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cbo_movDimenciones, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cbo_movNivel, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel13Layout.setVerticalGroup(
            jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel13Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel25)
                    .addComponent(cbo_movDimenciones, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel13Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel26)
                    .addComponent(cbo_movNivel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel14.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Dimencion 2"));

        jLabel30.setText("Dimencion:");

        jLabel31.setText("Campo:");

        cbo_movDimenciones2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--" }));
        cbo_movDimenciones2.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbo_movDimenciones2PopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        cbo_movNivel2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "--" }));

        javax.swing.GroupLayout jPanel14Layout = new javax.swing.GroupLayout(jPanel14);
        jPanel14.setLayout(jPanel14Layout);
        jPanel14Layout.setHorizontalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addComponent(jLabel30)
                        .addGap(18, 18, 18)
                        .addComponent(cbo_movDimenciones2, 0, 282, Short.MAX_VALUE))
                    .addGroup(jPanel14Layout.createSequentialGroup()
                        .addComponent(jLabel31)
                        .addGap(33, 33, 33)
                        .addComponent(cbo_movNivel2, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel14Layout.setVerticalGroup(
            jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel14Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel30)
                    .addComponent(cbo_movDimenciones2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel14Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel31)
                    .addComponent(cbo_movNivel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jTextArea4.setColumns(20);
        jTextArea4.setRows(5);
        jScrollPane15.setViewportView(jTextArea4);

        jButton20.setText("<>");
        jButton20.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton20ActionPerformed(evt);
            }
        });

        grupo_funciones.add(rd_sumar);
        rd_sumar.setSelected(true);
        rd_sumar.setText("Sumar");

        grupo_funciones.add(rd_promedio);
        rd_promedio.setText("Promedio");

        jPanel15.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "Restricción"));

        jLabel32.setText("Dimencion:");

        jLabel33.setText("Campo:");

        cbo_restriccion.addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
            public void popupMenuCanceled(javax.swing.event.PopupMenuEvent evt) {
            }
            public void popupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {
                cbo_restriccionPopupMenuWillBecomeInvisible(evt);
            }
            public void popupMenuWillBecomeVisible(javax.swing.event.PopupMenuEvent evt) {
            }
        });

        cbo_operador.setModel(new javax.swing.DefaultComboBoxModel(new String[] { ">", "<", ">=", "<=", "=", "<>" }));

        jLabel34.setText("Operador:");

        jLabel35.setText("Valor:");

        jButton23.setText("And");
        jButton23.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton23ActionPerformed(evt);
            }
        });

        jButton24.setText("Ok");
        jButton24.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton24ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel15Layout = new javax.swing.GroupLayout(jPanel15);
        jPanel15.setLayout(jPanel15Layout);
        jPanel15Layout.setHorizontalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel32)
                    .addComponent(jLabel33))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cbo_campo_restriccion, 0, 149, Short.MAX_VALUE)
                    .addComponent(cbo_restriccion, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel34))
                    .addGroup(jPanel15Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel35)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(cbo_operador, 0, 61, Short.MAX_VALUE)
                    .addComponent(txt_val_condicion))
                .addGap(18, 18, 18)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jButton23, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton24, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(45, Short.MAX_VALUE))
        );
        jPanel15Layout.setVerticalGroup(
            jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel15Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel32)
                    .addComponent(cbo_restriccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cbo_operador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel34)
                    .addComponent(jButton23))
                .addGap(18, 18, 18)
                .addGroup(jPanel15Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel33)
                    .addComponent(cbo_campo_restriccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel35)
                    .addComponent(txt_val_condicion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton24))
                .addContainerGap(27, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel11Layout = new javax.swing.GroupLayout(jPanel11);
        jPanel11.setLayout(jPanel11Layout);
        jPanel11Layout.setHorizontalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel11Layout.createSequentialGroup()
                                .addComponent(jLabel24)
                                .addGap(26, 26, 26)
                                .addComponent(cbo_movMetricas, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(rd_sumar)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(rd_promedio)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED))
                            .addGroup(jPanel11Layout.createSequentialGroup()
                                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jPanel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(jPanel14, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                                .addGap(21, 21, 21)))
                        .addComponent(jButton21)
                        .addGap(60, 66, Short.MAX_VALUE))
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane12, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE)
                    .addComponent(jScrollPane15))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton20)
                .addContainerGap())
        );
        jPanel11Layout.setVerticalGroup(
            jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel11Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jScrollPane12, javax.swing.GroupLayout.PREFERRED_SIZE, 281, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel11Layout.createSequentialGroup()
                                .addGap(3, 3, 3)
                                .addComponent(jLabel24))
                            .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(cbo_movMetricas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(rd_sumar)
                                .addComponent(rd_promedio)))
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel11Layout.createSequentialGroup()
                                .addGap(16, 16, 16)
                                .addComponent(jPanel13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jPanel14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel11Layout.createSequentialGroup()
                                .addGap(142, 142, 142)
                                .addComponent(jButton21)))
                        .addGap(12, 12, 12)))
                .addGap(18, 18, 18)
                .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addGroup(jPanel11Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton20, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane15, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jPanel11Layout.createSequentialGroup()
                        .addComponent(jPanel15, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 43, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Movimientos", new javax.swing.ImageIcon(getClass().getResource("/imagenes/movimiento.png")), jPanel11); // NOI18N

        jSplitPane1.setRightComponent(jTabbedPane1);

        getContentPane().add(jSplitPane1, java.awt.BorderLayout.CENTER);

        jToolBar1.setRollover(true);

        btnNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/nuevot.png"))); // NOI18N
        btnNuevo.setFocusable(false);
        btnNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNuevoActionPerformed(evt);
            }
        });
        jToolBar1.add(btnNuevo);

        btnAbrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/abrirt.png"))); // NOI18N
        btnAbrir.setFocusable(false);
        btnAbrir.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnAbrir.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnAbrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAbrirActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAbrir);

        jButton19.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/savet.png"))); // NOI18N
        jButton19.setFocusable(false);
        jButton19.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton19.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton19.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton19ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton19);

        getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START);

        mnuArchivo.setText("Archivo");

        mnuNuevo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        mnuNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/nuevo.png"))); // NOI18N
        mnuNuevo.setText("Nuevo");
        mnuNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuNuevoActionPerformed(evt);
            }
        });
        mnuArchivo.add(mnuNuevo);

        mnuAbrir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_MASK));
        mnuAbrir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/abrir.png"))); // NOI18N
        mnuAbrir.setText("Abrir");
        mnuAbrir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuAbrirActionPerformed(evt);
            }
        });
        mnuArchivo.add(mnuAbrir);

        mnuGuardar.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.CTRL_MASK));
        mnuGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/save.png"))); // NOI18N
        mnuGuardar.setText("Guardar");
        mnuGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuGuardarActionPerformed(evt);
            }
        });
        mnuArchivo.add(mnuGuardar);

        mnuSalir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        mnuSalir.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/salir.png"))); // NOI18N
        mnuSalir.setText("Salir");
        mnuSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuSalirActionPerformed(evt);
            }
        });
        mnuArchivo.add(mnuSalir);

        jMenuBar1.add(mnuArchivo);

        mnuEditar.setText("Editar");

        mnuConectar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/conectar.png"))); // NOI18N
        mnuConectar.setText("Conexion");
        mnuConectar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuConectarActionPerformed(evt);
            }
        });
        mnuEditar.add(mnuConectar);

        jMenuBar1.add(mnuEditar);

        mnuAyuda.setText("Ayuda");

        mnuAcercaDe.setText("Acerca de");
        mnuAcercaDe.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mnuAcercaDeActionPerformed(evt);
            }
        });
        mnuAyuda.add(mnuAcercaDe);

        jMenuBar1.add(mnuAyuda);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mnuNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuNuevoActionPerformed
      jdProyecto.setSize( 475, 300 );
      jdProyecto.setLocationRelativeTo(null);
      jdProyecto.setVisible(true); 
    }//GEN-LAST:event_mnuNuevoActionPerformed

    private void mnuSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuSalirActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mnuSalirActionPerformed

    private void mnuAcercaDeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuAcercaDeActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mnuAcercaDeActionPerformed

    private void mnuConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuConectarActionPerformed
        jdConexion.setSize(300, 250);
        jdConexion.setLocationRelativeTo( null );
        jdConexion.setVisible( true );
    }//GEN-LAST:event_mnuConectarActionPerformed

    private void txtUsuarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUsuarioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUsuarioActionPerformed

    private void btnConectarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnConectarActionPerformed
        txtPassword1.setText(txtPassword.getText());
        accPrincipal.conectar( txtUsuario.getText(),
                password(), txtNombreBD.getText() );
        jdConexion.setVisible(false);
    }//GEN-LAST:event_btnConectarActionPerformed

    private void cboTablaHechosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_cboTablaHechosMouseClicked

    }//GEN-LAST:event_cboTablaHechosMouseClicked

    private void cboTablaHechosItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_cboTablaHechosItemStateChanged
        
    }//GEN-LAST:event_cboTablaHechosItemStateChanged

    private void cboTablaHechosPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cboTablaHechosPopupMenuWillBecomeInvisible
        if( cboTablaHechos.getItemCount() > 0 )
            accPrincipal.setTablaHecho();
    }//GEN-LAST:event_cboTablaHechosPopupMenuWillBecomeInvisible

    private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
        accPrincipal.addMetrica();
        
      
    }//GEN-LAST:event_btnAddActionPerformed

    private void btnRemoveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnRemoveActionPerformed
        accPrincipal.removeMetrica();
    }//GEN-LAST:event_btnRemoveActionPerformed

    private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
        quitar_campo();
    }//GEN-LAST:event_jButton7ActionPerformed

    private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
        if(jtMetricas.getRowCount()<=0){
            JOptionPane.showMessageDialog(null,"Error, debe seleccionar almenos una metrica de la tabla de hecho","Sistema",JOptionPane.ERROR_MESSAGE);
        }
        else{
        tabla_hecho=cboTablaHechos.getSelectedItem().toString();
        propiedades.setTablaHecho(tabla_hecho);
        propiedades.setMetricas( (DefaultTableModel)jtMetricas.getModel() );
        jLabel8.setText(tabla_hecho);
        get_relaciones();
        }
        
          if(jtMetricas.getRowCount()>=2 && calculado==false){
            int res=JOptionPane.showConfirmDialog(null,"Ha seleccionado 2 o mas metricas, ¿desea introducir un campo calculado?","Sistema",JOptionPane.OK_CANCEL_OPTION);
            if(res==0){
                ventana_campo_calculado();
            }
        }
         
        
        
        
    }//GEN-LAST:event_jButton10ActionPerformed

    private void cmb_dimencionesPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cmb_dimencionesPopupMenuWillBecomeInvisible
        if(tabla_hecho!=null){
        mostrar_niveles(cmb_dimenciones.getSelectedItem().toString());
        }
        else{
            JOptionPane.showMessageDialog(null,"Error,aun no ha establecido la tabla de hecho","Error", JOptionPane.ERROR_MESSAGE);

        }
    }//GEN-LAST:event_cmb_dimencionesPopupMenuWillBecomeInvisible

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        // TODO add your handling code here:
        if(modelo_campos_reales.size()>0){
        dimencion_actual.activar_dimencion();
        habilitar_dimencion();
        }
        else{
            JOptionPane.showMessageDialog(null,"Debe seleccionar almenos un campo para esta jeraquia","Error", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
        if(modelo_dim_reales.getSize()<=0){
            dimencion_actual.desacticar_dimencion();
        }
        
        deshabilitar_dimencion();
    }//GEN-LAST:event_jButton4ActionPerformed

    private void jList1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseClicked
       
        seleccionar_campos(modelo_dimenciones.get(jList1.getSelectedIndex()).toString());
    }//GEN-LAST:event_jList1MouseClicked

    private void btnCancelarConActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarConActionPerformed
        jdConexion.setVisible(false);
    }//GEN-LAST:event_btnCancelarConActionPerformed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
      agregar_campo();
  
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        setOperacion( GENERAR_SCRIPT_ESTRELLA );
        setDescripcion("Generando Script...");
        Thread t = new Thread( this );
        t.start();
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
      
      set_cortapapeles(modelo1.get(jList5.getSelectedIndex()).toString());
        
     
    }//GEN-LAST:event_jButton6ActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        // TODO add your handling code here:
        jPanel4.setVisible(true);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
        jPanel4.setVisible(false);
    }//GEN-LAST:event_jButton9ActionPerformed

    private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
        String[] fila=new String[]{"--",jTextField1.getText(),jComboBox1.getSelectedItem().toString(),txt_definicion.getText()};
        accPrincipal.add_campo_calculado(fila);
        jPanel4.setVisible(false);
        
    }//GEN-LAST:event_jButton8ActionPerformed

    private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
        // TODO add your handling code here:
        jdCampos_calculados.setVisible(false);
    }//GEN-LAST:event_jButton11ActionPerformed

    private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
       ventana_campo_calculado();
       calculado=true;
    }//GEN-LAST:event_jButton12ActionPerformed

    private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
        setOperacion( EJECUTAR_SCRIPT );
        setDescripcion("Ejecutando script estrella...");
        Thread t = new Thread( this );
        t.start();
    }//GEN-LAST:event_jButton15ActionPerformed

    private void jComboBox2PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jComboBox2PopupMenuWillBecomeInvisible
        accPrincipal.campoFecha(jComboBox2.getSelectedItem());
    }//GEN-LAST:event_jComboBox2PopupMenuWillBecomeInvisible

    private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
        agregarDimensionTiempo();
    }//GEN-LAST:event_jButton13ActionPerformed

    private void txtUProyectoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUProyectoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUProyectoActionPerformed

    private void txtUBackUPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUBackUPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUBackUPActionPerformed

    private void btnUProyectoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUProyectoActionPerformed
        seleccionar_ubicacion(txtUProyecto, JFileChooser.DIRECTORIES_ONLY, "Crear Proyecto");
    }//GEN-LAST:event_btnUProyectoActionPerformed

    private void txtUsuario1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtUsuario1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtUsuario1ActionPerformed

    
    private void btnCrearProyectoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCrearProyectoActionPerformed
        setOperacion( CREAR_PROYECTO );
        setDescripcion("Conectando Base de datos...");
        Thread t = new Thread( this );
        t.start();
    }//GEN-LAST:event_btnCrearProyectoActionPerformed

    private void btnUBackUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUBackUpActionPerformed
        seleccionar_ubicacion(txtUBackUP, JFileChooser.FILES_ONLY, "Seleccionar BackUp");
    }//GEN-LAST:event_btnUBackUpActionPerformed

    private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
        setOperacion( GENERAR_SCRIPT_DATOS );
        setDescripcion("Generando Script de datos...");
        Thread t = new Thread( this );
        t.start();
    }//GEN-LAST:event_jButton17ActionPerformed

    private void jButton18ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton18ActionPerformed
        setOperacion( EJECUTAR_SCRIPT_DATOS );
        setDescripcion("Ejecutando script de datos...");
        Thread t = new Thread( this );
        t.start();
    }//GEN-LAST:event_jButton18ActionPerformed

    private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
        // TODO add your handling code here:
        grafica g=new grafica(lista_jerarquia);
        g.graficar(propiedades.getPath(),accPrincipal.getNombreBD(),tabla_hecho);
        
        
        JPanel_imagen jPanelConFondo2 = new JPanel_imagen();
        jPanelConFondo2.setBounds(250,30, 450,450);
        
        propiedades.getPath();
        System.out.println(g.fileOutputPath);
        Image imagenExterna = new ImageIcon(g.fileOutputPath).getImage();

        jPanelConFondo2.setImagen(imagenExterna);
        jPanel10.add(jPanelConFondo2);
        jPanel10.repaint();
        this.repaint();
    }//GEN-LAST:event_jButton16ActionPerformed

    private void btnCancelarPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarPActionPerformed
        jdProyecto.setVisible(false);
    }//GEN-LAST:event_btnCancelarPActionPerformed

    private void mnuGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuGuardarActionPerformed
        accPrincipal.guardar(propiedades);
    }//GEN-LAST:event_mnuGuardarActionPerformed

    private void mnuAbrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mnuAbrirActionPerformed
        manejoProyecto = new JFileChooser();
        
        manejoProyecto.setFileSelectionMode( JFileChooser.FILES_ONLY );
        
        int seleccion = manejoProyecto.showOpenDialog( this );
        
        if( seleccion == JFileChooser.APPROVE_OPTION ){
            File f = manejoProyecto.getSelectedFile();
            try{
            	//String nombre = f.getName();
            	String path = f.getAbsolutePath();
                Propiedades p = accPrincipal.abrir(path );
                if( p != null ) propiedades = p;
                tabla_hecho = propiedades.getTabla_hecho();
                jLabel8.setText(tabla_hecho);
                this.setTitle(propiedades.getnProyecto());
                get_relaciones();
            }
            catch( Exception e){ e.printStackTrace(); }
        }
    }//GEN-LAST:event_mnuAbrirActionPerformed

    private void btnNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNuevoActionPerformed
      jdProyecto.setSize( 475, 300 );
      jdProyecto.setLocationRelativeTo(null);
      jdProyecto.setVisible(true); 
    }//GEN-LAST:event_btnNuevoActionPerformed

    private void btnAbrirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAbrirActionPerformed
        manejoProyecto = new JFileChooser();
        
        manejoProyecto.setFileSelectionMode( JFileChooser.FILES_ONLY );
        
        int seleccion = manejoProyecto.showOpenDialog( this );
        
        if( seleccion == JFileChooser.APPROVE_OPTION ){
            File f = manejoProyecto.getSelectedFile();
            try{
            	//String nombre = f.getName();
            	String path = f.getAbsolutePath();
                Propiedades p = accPrincipal.abrir(path );
                if( p != null ) propiedades = p;
                tabla_hecho = propiedades.getTabla_hecho();
                jLabel8.setText(tabla_hecho);
                this.setTitle(propiedades.getnProyecto());
                get_relaciones();
            }
            catch( Exception e){ e.printStackTrace(); }
        }
    }//GEN-LAST:event_btnAbrirActionPerformed

    private void jButton19ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton19ActionPerformed
        accPrincipal.guardar(propiedades);
    }//GEN-LAST:event_jButton19ActionPerformed

    private void cboTablaHechosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cboTablaHechosActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cboTablaHechosActionPerformed

    private void cbo_movDimencionesPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbo_movDimencionesPopupMenuWillBecomeInvisible
        String aux=cbo_movDimenciones.getSelectedItem().toString();
        
        nivel_movimiento(aux,cbo_movNivel);
        
    }//GEN-LAST:event_cbo_movDimencionesPopupMenuWillBecomeInvisible

    private void jButton21ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton21ActionPerformed
        generar_consulta_cubo();
    }//GEN-LAST:event_jButton21ActionPerformed

    private void cbo_movNivelPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbo_movNivelPopupMenuWillBecomeInvisible
     
    }//GEN-LAST:event_cbo_movNivelPopupMenuWillBecomeInvisible

    private void cbo_movDimencionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbo_movDimencionesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbo_movDimencionesActionPerformed

    private void cbo_movDimenciones2PopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbo_movDimenciones2PopupMenuWillBecomeInvisible
        String aux=cbo_movDimenciones2.getSelectedItem().toString();
         nivel_movimiento(aux,cbo_movNivel2);
    }//GEN-LAST:event_cbo_movDimenciones2PopupMenuWillBecomeInvisible

    private void jButton20ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton20ActionPerformed
       set_cortapapeles(jTextArea4.getText());
    }//GEN-LAST:event_jButton20ActionPerformed

    private void cbo_restriccionPopupMenuWillBecomeInvisible(javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_cbo_restriccionPopupMenuWillBecomeInvisible
        
        String aux=cbo_restriccion.getSelectedItem().toString();
         nivel_movimiento(aux,cbo_campo_restriccion);

    }//GEN-LAST:event_cbo_restriccionPopupMenuWillBecomeInvisible

    private void jButton24ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton24ActionPerformed
        String tabla= cbo_restriccion.getSelectedItem().toString();
        
        if(!restriccion_llave.contains(tabla)){
            restriccion_llave.add(tabla);
        }
        
        restriccion_campo+="\n"+tabla+"."+cbo_campo_restriccion.getSelectedItem().toString()+
                cbo_operador.getSelectedItem().toString()+txt_val_condicion.getText();
                
    }//GEN-LAST:event_jButton24ActionPerformed

    private void jButton23ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton23ActionPerformed
        restriccion_campo+="\n and \n";
    }//GEN-LAST:event_jButton23ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Principal().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAbrir;
    private javax.swing.JButton btnAdd;
    private javax.swing.JButton btnCancelarCon;
    private javax.swing.JButton btnCancelarP;
    private javax.swing.JButton btnConectar;
    private javax.swing.JButton btnCrearProyecto;
    private javax.swing.JButton btnNuevo;
    private javax.swing.JButton btnRemove;
    private javax.swing.JButton btnUBackUp;
    private javax.swing.JButton btnUProyecto;
    public javax.swing.JComboBox cboTablaHechos;
    private javax.swing.JComboBox cbo_campo_restriccion;
    private javax.swing.JComboBox cbo_movDimenciones;
    private javax.swing.JComboBox cbo_movDimenciones2;
    private javax.swing.JComboBox cbo_movMetricas;
    private javax.swing.JComboBox cbo_movNivel;
    private javax.swing.JComboBox cbo_movNivel2;
    private javax.swing.JComboBox cbo_operador;
    private javax.swing.JComboBox cbo_restriccion;
    private javax.swing.JComboBox cmb_dimenciones;
    private javax.swing.ButtonGroup grupo_funciones;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton18;
    private javax.swing.JButton jButton19;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton20;
    private javax.swing.JButton jButton21;
    private javax.swing.JButton jButton23;
    private javax.swing.JButton jButton24;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JCheckBox jCheckBox5;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JList jList2;
    private javax.swing.JList jList3;
    private javax.swing.JList jList4;
    private javax.swing.JList jList5;
    private javax.swing.JList jList6;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel11;
    private javax.swing.JPanel jPanel13;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JPanel jPanel8;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane12;
    private javax.swing.JScrollPane jScrollPane15;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTabbedPane jTabbedPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextArea jTextArea2;
    private javax.swing.JTextArea jTextArea4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JDialog jdCampos_calculados;
    private javax.swing.JDialog jdConexion;
    public javax.swing.JDialog jdProgreso;
    public javax.swing.JDialog jdProyecto;
    public javax.swing.JProgressBar jpbProgreso;
    public javax.swing.JScrollPane jspTablaHecho;
    public javax.swing.JTable jtDatosTabla;
    public javax.swing.JTable jtMetricas;
    public javax.swing.JTree jtProyecto;
    public javax.swing.JLabel lblMensajeProgreso;
    private javax.swing.JMenuItem mnuAbrir;
    private javax.swing.JMenuItem mnuAcercaDe;
    private javax.swing.JMenu mnuArchivo;
    private javax.swing.JMenu mnuAyuda;
    private javax.swing.JMenuItem mnuConectar;
    private javax.swing.JMenu mnuEditar;
    private javax.swing.JMenuItem mnuGuardar;
    private javax.swing.JMenuItem mnuNuevo;
    private javax.swing.JMenuItem mnuSalir;
    private javax.swing.JRadioButton rd_promedio;
    private javax.swing.JRadioButton rd_sumar;
    private javax.swing.JTextField txtNProyecto;
    private javax.swing.JTextField txtNombreBD;
    private javax.swing.JTextField txtNombreBD1;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JPasswordField txtPassword1;
    private javax.swing.JTextField txtPuerto;
    private javax.swing.JTextField txtServidor;
    private javax.swing.JTextField txtUBackUP;
    private javax.swing.JTextField txtUProyecto;
    private javax.swing.JTextField txtUsuario;
    private javax.swing.JTextField txtUsuario1;
    private javax.swing.JTextArea txt_definicion;
    private javax.swing.JTextField txt_val_condicion;
    // End of variables declaration//GEN-END:variables
    AccionesPrincipal accPrincipal;
    
    
    public void nivel_movimiento(String campo,JComboBox combo){
        boolean encontrado=false;
        combo.removeAllItems();
        combo.addItem("--");
        int i=0;
        
        while(i<lista_jerarquia.size() && encontrado!=true){
            nodo_arbol temp=lista_jerarquia.get(i);
            
            if(temp.nombre_nodo.equals(campo)){
                dimencion_mov=temp;
                
                if(temp.estado){
                    for(int m=0;m<temp.campos.size();m++){
                        
                        String []tp=(String [])temp.campos.get(m);
                        if(tp[3].equals("1"))
                            combo.addItem(temp.nombre_nodo+"_"+tp[1]);
                    }
                }
                
                for(int j=0;j<temp.lista_hijos.size();j++){
                    if(temp.lista_hijos.get(j).estado){
                        
                        for(int x=0;x<temp.lista_hijos.get(j).campos.size();x++){
                            String []z=(String [])temp.lista_hijos.get(j).campos.get(x);
                            combo.addItem(temp.lista_hijos.get(j).nombre_nodo+"_"+z[1]);
                        }
                        
                    }
                }
                encontrado=true;
            }
            i++;
        }
        
    }
    
    
    
    
    public void set_cortapapeles(String cadena){
         Clipboard cl=Toolkit.getDefaultToolkit().getSystemClipboard();
      
      
      StringSelection a=new StringSelection(cadena);
      cl.setContents(a, a);
    }
    
    public void generar_consulta_cubo(){
        AccionesPrincipal acc=new AccionesPrincipal(this);
        acc.conectar(accPrincipal.user, accPrincipal.password,accPrincipal.base_datos+"_estrella");
        
        String from="";
        String where="";
        
        String cadena="SELECT ";
        String t1=cbo_movDimenciones.getSelectedItem().toString();
        String c1=cbo_movNivel.getSelectedItem().toString();
        
        cadena+=t1+"."+c1;
        
        String llave_t1=get_llave(acc.get_campos(t1));
        
        String t2=cbo_movDimenciones2.getSelectedItem().toString();
        String c2=cbo_movNivel2.getSelectedItem().toString();
        String llave_t2=get_llave(acc.get_campos(t2));
        
        String valor=tabla_hecho+"."+tabla_hecho+"_"+cbo_movMetricas.getSelectedItem().toString();;
        
        if(rd_sumar.isSelected()){
            valor="sum("+valor+")";
        }
        else
            if(rd_promedio.isSelected()){
                valor="avg("+valor+")";
            }
            
        cadena+=","+t2+"."+c2+","+valor+" "+cbo_movMetricas.getSelectedItem().toString();
        from="\nfrom\n"+t1+" "+t1+","+t2+" "+t2+","+tabla_hecho+" "+tabla_hecho;      
        where="\nwhere\n "+t1+"."+llave_t1+"="+tabla_hecho+"."+llave_t1+" and\n"+t2+"."+llave_t2+"="+tabla_hecho+"."+llave_t2;
        
        for(String nombre: restriccion_llave){
            from+=","+nombre+" "+nombre;
            String llave=get_llave(acc.get_campos(nombre));
            where+=" and "+nombre+"."+llave+"="+tabla_hecho+"."+llave+"\n";
        }
        
        if(!restriccion_campo.isEmpty()){
        where+=" and "+restriccion_campo;
        }
        
        cadena+=from+where;
        cadena+="\ngroup by "+t1+"."+c1+","+t2+"."+c2;
        
        
        this.jTextArea4.setText(cadena);
        ArrayList<String[]> resultado= acc.consulta(cadena);
        DefaultTableModel dtmModelo = new DefaultTableModel();
        dtmModelo.addColumn(cbo_movNivel.getSelectedItem());
        dtmModelo.addColumn(cbo_movNivel2.getSelectedItem());
        dtmModelo.addColumn(cbo_movMetricas.getSelectedItem());
        for( String[] r : resultado ){
            dtmModelo.addRow( r );
        }
        jTable1.setModel(dtmModelo);
        
        restriccion_llave.clear();
        restriccion_campo="";
    }
    
    public String get_llave(ArrayList lst){
        int i=0;
        
        while(i<lst.size()){
            String [] temp=(String [])lst.get(i);
            if(temp[0].equals("PK")){
                return temp[1];
            }
                i++;
        }
        
        return null;
    }
    
    
    
    public String query_full_tabla_hecho()
    {
        String bd_actual=this.accPrincipal.base_datos;
        String user=this.accPrincipal.user;
        String password=this.accPrincipal.password;
        String linkeado="'dbname="+bd_actual+" user="+user+" password="+password+"',";
        accPrincipal.progresando(80);
        String [] partes=campos_tabla_hecho().split(";");
        
        String cadena="";
        nodo_arbol tabla_hechos=this.get_metricas();
        cadena+="INSERT INTO "+tabla_hechos.nombre_nodo+"("+partes[1]+")\n";
        cadena+="SELECT * FROM DBLINK("+linkeado+ "\n";
        cadena+="'"+etl_tabla_hecho()+"') \n";
        cadena+="AS T1("+partes[0]+");";
        accPrincipal.progresando(100);
        return cadena;
    }
    
    
    public String campos_tabla_hecho()
    {
       String cadena="";
       String cadena2="";

        for(int i=0;i<campos_tblHecho2.size();i++)
        {
            if (i==0)
            {
                cadena+=campos_tblHecho2.get(i);
                cadena2+=campos_tblHecho2.get(i).substring(0,campos_tblHecho2.get(i).lastIndexOf(" "));
            }
            else
            {
                cadena +=","+campos_tblHecho2.get(i);
                cadena2+=","+campos_tblHecho2.get(i).substring(0,campos_tblHecho2.get(i).lastIndexOf(" "));
            }

        }
        return cadena+";"+cadena2;
    }
    
     public Connection crearConnection(String usuario, String password,String bd)
    {
        Conexion.setUsuario( usuario, password );
        Connection con= Conexion.getConexion( bd );

        return con;
    }

    public String etl_tabla_hecho(){
        String select="select ";
        
        if(campos_tblHecho.size()>1){
        for(int i=0;i<campos_tblHecho.size();i++){
             if (i==0)
            {
                select+=campos_tblHecho.get(i);
            }
            else
            {
                select +=", "+campos_tblHecho.get(i);
            }
            
        }
        }
        
        select+="\n from\n";
        String[]a=accPrincipal.lista_tablas();
        
        for( int i=0;i<a.length;i++ ){
            
            if(i==0){
                select+=a[i];
            }
            else{
                select+=","+a[i];
            }
           
        }
        
        
        select+="\nwhere\n ";
                
        ArrayList condiciones=  get_condiciones(tabla_hecho);
      for(int i=0;i<condiciones.size();i++){
          
          if(i==0){
              select+=condiciones.get(i);
          }
          else{
          select+="\nand "+condiciones.get(i);
          }
      }
                
                return select;
    }
    
    
    public javax.swing.JComboBox getCboTiempo()
    {
        return jComboBox2;
    }

    public javax.swing.DefaultListModel getListaCampos()
    {
        return modelo_campo_fecha;
    }
    
    public void ventana_campo_calculado(){
        jdCampos_calculados.setSize(560, 360);
                                
                for(int i=0;i<jtMetricas.getRowCount();i++){
                    modelo1.addElement((String)jtMetricas.getValueAt(i, 1));
                }
                
                jdCampos_calculados.setLocationRelativeTo( null );
                jdCampos_calculados.setVisible( true );
    }
    
    
    public void get_relaciones(){
        
        lista_jerarquia=get_jerarquia(tabla_hecho);
        cmb_dimenciones.removeAllItems();
        for(int i=0;i<lista_jerarquia.size();i++){
            cmb_dimenciones.addItem(lista_jerarquia.get(i).nombre_nodo);
        }
    }
    
    
    
    public LinkedList<nodo_arbol> get_jerarquia(String nom_tabla){
        boolean entro=false;
        LinkedList<nodo_arbol> tmp=new LinkedList<nodo_arbol>();
        try {
            
          ResultSet rs = accPrincipal.get_relaciones(nom_tabla); 
          while(rs.next()){
              
              LinkedList<nodo_arbol> x= get_jerarquia(rs.getString("tabla_foranea"));
              
              
               for(int i=0;i<x.size();i++){
                  nodo_arbol tempp=x.get(i);
                  tempp.add_hijo(new nodo_arbol(nom_tabla,accPrincipal.get_campos(nom_tabla)));
                  tmp.add(tempp);
              }
              
              entro=true;
          }
         if(!entro){
          LinkedList<nodo_arbol> temp11=new LinkedList<nodo_arbol>();
          temp11.add(new nodo_arbol(nom_tabla,accPrincipal.get_campos(nom_tabla)));
         return temp11;
         }
         else{
             return tmp;
         }
          
        } catch (SQLException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
    
    
    public void mostrar_niveles(String cad){
         modelo_dimenciones.removeAllElements();
       
        dimencion_actual=buscar_dimencion(cad);
        
        modelo_dimenciones.addElement(dimencion_actual.nombre_nodo);
                for(int j=0;j<dimencion_actual.lista_hijos.size()-1;j++){
                    modelo_dimenciones.addElement(dimencion_actual.lista_hijos.get(j).nombre_nodo);
                }
    }
    
     public nodo_arbol buscar_dimencion(String nombre){
        int i=0; 
        while(i<lista_jerarquia.size()){
            if(lista_jerarquia.get(i).nombre_nodo.equals(nombre)){
               return lista_jerarquia.get(i);

            }
            i++;
        }
        return null;
    }
     
     
     public void agregar_campo(){
          try{
        String tabla=modelo_dimenciones.get(jList1.getSelectedIndex()).toString();
        String campo=modelo_campos.get(jList2.getSelectedIndex()).toString();
        
        modelo_campos.remove(jList2.getSelectedIndex());
        modelo_campos_reales.addElement(campo);
        dimencion_actual.visibilidad_campo(tabla, campo,"1");

         }
         catch(Exception e){
             JOptionPane.showMessageDialog(null,"No ha seleccionado ningun campo para agregar","Error", JOptionPane.ERROR_MESSAGE);
         }
     }
     
     
     
     public void quitar_campo(){
          try{
        String tabla=modelo_dimenciones.get(jList1.getSelectedIndex()).toString();
        String campo=modelo_campos.get(jList2.getSelectedIndex()).toString();
        
        modelo_campos.addElement(campo);
        modelo_campos_reales.remove(jList4.getSelectedIndex());
        dimencion_actual.visibilidad_campo(tabla, campo,"0");

         }
         catch(Exception e){
             JOptionPane.showMessageDialog(null,"No ha seleccionado ningun campo para eliminar","Error", JOptionPane.ERROR_MESSAGE);
         }
     }
     
     
     
     
     public void habilitar_dimencion(){
         try{
         String dim=modelo_dimenciones.get(jList1.getSelectedIndex()).toString();
        modelo_dimenciones.remove(jList1.getSelectedIndex());
        modelo_dim_reales.addElement(dim);
        dimencion_actual.habilitar_dimencion(dim,true);
        modelo_campos.removeAllElements();
        modelo_campos_reales.removeAllElements();
         }
         catch(Exception e){
             JOptionPane.showMessageDialog(null,"No ha seleccionado una jerarquia para agregar","Error", JOptionPane.ERROR_MESSAGE);
         }
     }
    
    public void deshabilitar_dimencion(){
        try{
         String dim=modelo_dim_reales.get(jList3.getSelectedIndex()).toString();
        modelo_dim_reales.remove(jList3.getSelectedIndex());
        modelo_dimenciones.addElement(dim);
        dimencion_actual.habilitar_dimencion(dim,false);
        }
        catch(Exception ee){
            JOptionPane.showMessageDialog(null,"No ha seleccionado una jerarquia para remover","Error", JOptionPane.ERROR_MESSAGE);

        }
     }
    
    
     public void seleccionar_campos(String nombre){
         modelo_campos.removeAllElements();
         if(dimencion_actual.nombre_nodo.equals(nombre)){
             
             for(int i=0;i<dimencion_actual.campos.size();i++){
                 String [] a=(String[])dimencion_actual.campos.get(i);
                 modelo_campos.addElement(a[1]);
             }
         }
         else{
         nodo_arbol aux=dimencion_actual.buscar_jerarquia(nombre);
         
        
          for(int j=0;j<aux.campos.size();j++){
                String [] b=(String[])aux.campos.get(j);
                 modelo_campos.addElement(b[1]);
             }
         }
         
         

    }
     ///////////////////////Este es el metodo que genera el script del modelo estrella
     ///////////////////////a partir de la base de datos seleccionada
     public String generar_script_estrella()
     {
         String cad="";/////////////cadena con el script
         String tab_hechos="";////////////cadena con los campos que se agregaran a la tabla de hechos de cada dimension, la llave primaria
         String tab_hechos_aux="";////////////cadena con la union de los distintos campos que se agregaran a la tabla de hechos, la union del varios tab_hechos
         String pktab_hechos="";/////////////cadena con la llave primaria de la tabla de hechos
         String fktab_hechos="";/////////////cadena con las llaves foraneas de la tabla de hechos
          String prueba="";
         String prueba1="";
         String prueba2="";
         String prueba3="";
         String prueba4="";
         String prueba5="";
          cbo_movDimenciones.removeAllItems();
          cbo_movDimenciones2.removeAllItems();

         cad="\nDROP DATABASE if exists "+this.accPrincipal.getNombreBD()+"_estrella"+";\n\n";

         cad+="\nCREATE DATABASE "+this.accPrincipal.getNombreBD()+"_estrella"+";\n\n";
         accPrincipal.progresando(10);
         /////////ejecutar el script sin especificar una base de datos
         this.accPrincipal.ejecutarScriptBD(cad,"");

         cad="";

         for(int i=0;i<lista_jerarquia.size();i++)////////////recorrer las dimensiones
         {
             
             
             String pk="";/////////cadena con la llave primaria de cada dimension
             String tmp="";
             String tmp2="";
             tab_hechos="";
             nodo_arbol aux=lista_jerarquia.get(i);
             if(aux.dimencion_activa){
                 
                 //para los movimientos
             cbo_movDimenciones.addItem(aux.nombre_nodo);
             cbo_movDimenciones2.addItem(aux.nombre_nodo);
             cbo_restriccion.addItem(aux.nombre_nodo);
                 

               cad+="CREATE TABLE "+aux.nombre_nodo+" (\n";

               if(aux.estado){

                   for(int x=0;x<aux.campos.size();x++){///////////////recorrer los campos de la tabla
                       String []a=(String [])aux.campos.get(x);


                       if(a[0].equals("PK")) /////////comprueba si el campo es llave primaria
                       {
                           if(!pk.equals(""))
                           {
                               pk+=","+aux.nombre_nodo+"_"+a[1];
                               tmp=aux.nombre_nodo+"."+a[1];
                               tmp2=aux.nombre_nodo+"_"+a[1]+" "+a[2];
                           }
                           else
                           {
                               pk=aux.nombre_nodo+"_"+a[1];
                               tmp=aux.nombre_nodo+"."+a[1];
                               tmp2=aux.nombre_nodo+"_"+a[1]+" "+a[2];
                           }
                           
                           cad+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";                  
                           tab_hechos+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+" NOT NULL ,\n";
                       }

                       if(a[3].equals("1"))////////////el campo esta seleccionado y se agrega al script
                       {
                           cad+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+" NULL,\n";
                           prueba+=aux.nombre_nodo+"_"+a[1]+","+" ";
                       }
                       
                   }
               }


               for(int j=0;j<aux.lista_hijos.size()-1;j++)////////////recorrer las tablas que componen la dimension
               {
                   nodo_arbol aux2=aux.lista_hijos.get(j);
                   if(aux2.estado){
                       pk="";
                       tmp="";
                       tab_hechos="";

                   for(int z=0;z<aux2.campos.size();z++){/////////////recorrer los campos de la tabla
                       String []a=(String [])aux2.campos.get(z);

                       if(a[0].equals("PK"))/////////comprueba si el campo es llave primaria
                       {
                           if(!pk.equals(""))
                           {
                               pk+=","+aux2.nombre_nodo+"_"+a[1];
                               tmp=aux2.nombre_nodo+"."+a[1];
                               tmp2=aux2.nombre_nodo+"_"+a[1]+" "+a[2];
                           }
                           else
                           {
                               pk=aux2.nombre_nodo+"_"+a[1];
                               tmp=aux2.nombre_nodo+"."+a[1];
                               tmp2=aux2.nombre_nodo+"_"+a[1]+" "+a[2];
                           }
                           
                           cad+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";                           
                           tab_hechos+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+" NOT NULL ,\n";
                       }

                       if(a[3].equals("1")) ///////////////////////////el campo esta seleccionado y se agrega al script
                       {
                           cad+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+" NULL,\n";
                       }
                       

                   }
                   }

               }
               cad+="CONSTRAINT pk_"+aux.nombre_nodo +" PRIMARY KEY ("+pk+")\n";
               System.out.println("llave primaria "+aux.nombre_nodo+" -> "+tmp);
               campos_tblHecho.add(tmp);
               campos_tblHecho2.add(tmp2);
               prueba3=aux.nombre_nodo;               
               prueba4 = pk;
               cad+=");\n\n";
               
               if(fktab_hechos.equals("")){
                   fktab_hechos+="FOREIGN KEY ("+pk+") REFERENCES "+aux.nombre_nodo+"\n";
                   prueba1 = pk;
               }
               else
               {
                   fktab_hechos+=", FOREIGN KEY ("+pk+") REFERENCES "+aux.nombre_nodo+"\n";
                   prueba1 = pk;
               }

               if(pktab_hechos.equals(""))
                    pktab_hechos+=pk;
               else
                    pktab_hechos+=","+pk;
             }
             tab_hechos_aux+=tab_hechos;

         }
        accPrincipal.progresando(50);
         ///////////////creacion de la tabla de hechos/////////////////////////
        nodo_arbol tabla_hechos=this.get_metricas();
        cad+="CREATE TABLE "+tabla_hechos.nombre_nodo+" (\n";

        cad+="\tcorrelativo_1 serial NOT NULL,\n";
        cad+=tab_hechos_aux;
       
      

        for(int z=0;z<tabla_hechos.campos.size();z++){
           String []a=(String [])tabla_hechos.campos.get(z);
           if(!a[3].isEmpty()){
               campos_tblHecho.add(a[3]);
               campos_tblHecho2.add(tabla_hechos.nombre_nodo+"_"+a[1]+" "+a[2]);
               
           }
           else{
               campos_tblHecho.add(tabla_hechos.nombre_nodo+"."+a[1]);
               campos_tblHecho2.add(tabla_hechos.nombre_nodo+"_"+a[1]+" "+a[2]);
           }
         
           cbo_movMetricas.addItem(a[1]);
           cad+="\t"+tabla_hechos.nombre_nodo+"_"+a[1]+" "+a[2]+" NULL,\n";
          
           
       }
        accPrincipal.progresando(90);
    //    jTextArea3.append("\n");
    //    jTextArea3.append("FROM" + " " + tabla_hechos.nombre_nodo);
        if (prueba3!=""){
      //      jTextArea3.append(","+" "+prueba3);
      //      jTextArea3.append("\n");
      //      jTextArea3.append("WHERE "+prueba3+"."+prueba4 +" "+"="+" "+tabla_hechos.nombre_nodo+"."+prueba1);
        }

        cad+="CONSTRAINT pk_"+tabla_hechos.nombre_nodo+" PRIMARY KEY (correlativo_1)\n";
        cad+=","+fktab_hechos;///////fktab_hechos trae las fk de la tabla de hechos
        cad+=");\n\n";
        
        String secuencia="\nCREATE SEQUENCE sec_"+tabla_hechos.nombre_nodo+"\n";
        secuencia+="\tINCREMENT 1\n\tMINVALUE 1\n\tSTART 1\n\tCACHE 1;\n";
        secuencia+="ALTER TABLE sec_"+tabla_hechos.nombre_nodo+" OWNER TO postgres;";
        
        secuencia+="ALTER TABLE "+tabla_hechos.nombre_nodo+ "\nALTER COLUMN correlativo_1\nSET DEFAULT NEXTVAL('sec_"+tabla_hechos.nombre_nodo+"');";
        accPrincipal.progresando(100);
         return cad+"\n"+secuencia;
         
     }

     ////////////metodo que genera dimension tiempo, tipo java.util.Date (sujeto a cambios!!!!!!)
     public boolean generarDimTiempo(java.util.Date fechainicio, java.util.Date fechafin, boolean anio,boolean semestre, boolean trimestre, boolean mes, boolean dia)
     {
         boolean exitoso=false;

         ////////////codigo para generar dimension tiempo

         return exitoso;
     }
     
/**
 * Construye nodo para el árbol que contiene las jerarquías.
 */
    void agregarDimensionTiempo()
    {
        ArrayList camposTiempo = new ArrayList();
        String[] pk = {"PK", "id_tiempo", "integer", "0"};
        camposTiempo.add(pk);
        
        if(jCheckBox1.isSelected())//si está chequeado año
        {
            String[] val = {"--", "anio", "integer", "1"};
            camposTiempo.add(val);
        }
        if(jCheckBox2.isSelected())//si está chequeado semestre
        {
            String[] val = {"--", "semestre", "character varying(30)", "1"};
            camposTiempo.add(val);
        }
        if(jCheckBox3.isSelected())//si está chequeado trimestre
        {
            String[] val = {"--", "trimestre", "character varying(30)", "1"};
            camposTiempo.add(val);
        }
        if(jCheckBox4.isSelected())//si está chequeado mes
        {
            String[] val = {"--", "mes", "character varying(30)", "1"};
            camposTiempo.add(val);
        }
        if(jCheckBox5.isSelected())//si está chequeado dia
        {
            String[] val = {"--", "dia", "integer", "1"};
            camposTiempo.add(val);
        }
        nodo_arbol t = new nodo_arbol();
        t.nombre_nodo = "dimension_tiempo";
        t.activar_dimencion();
        t.estado = true;
        t.campos = camposTiempo;
        t.lista_hijos = new LinkedList<nodo_arbol>();
        lista_jerarquia.add(t);
    }

     
     //este es el metodo jala los datos de la tabla de las metricas seleccionadas y las pasa a una estructura
     //de nodo_arbol, en este nodo, la ultima posicion de cada arreglo no almacena si el campo se mira o no
     //sino como son metricas el ultimo campo contiene las operaciones para calcular el campo
     public nodo_arbol get_metricas(){
         ArrayList lst=new ArrayList();
         for(int i=0;i<jtMetricas.getRowCount();i++){
              String [] a=new String[4];
             for(int j=0;j<=3;j++){
                 a[j]=(String)jtMetricas.getModel().getValueAt(i, j);
             }
             lst.add(a);
         }
         return new nodo_arbol(jtMetricas.getName().toString(),lst);
     }
     
///////////////////////PARA VOLCAR LOS DATOS METODO-------------------------------------------------------
     
     public String generar_script_datos()
     {
         
        String bd_actual=accPrincipal.getNombreBD()+"_estrella";
        String user="postgres";
        String password=accPrincipal.password;
        String linkeado="'dbname="+bd_actual+" user="+user+" password="+password+"',";


         String cad_script="";/////////////cadena con el script
         String tablas=""; //CADENA CON TABLAS EN EL JOIN
         String tablas_aux="";
         


         String cadena_tabla_hechos="";//cadena con el query de datos de la tabla de hechos
         String tablas_join=""; // cadena con las tablas a unir en el query
         

         /////////ejecutar el script sin especificar una base de datos
         this.accPrincipal.ejecutarScriptBD(cad_script,"");

         cad_script="";

         for(int i=0;i<lista_jerarquia.size();i++)////////////recorrer las dimensiones
         {
            String pk="";/////////cadena con la llave primaria de cada dimension
            String campos=""; //CADENA CON CAMPOS Y TIPO DEL CAMPO EN LA CONSULTA DEL JOIN
            //String campos_aux="";
            String campos_sin=""; //CADENA CON CAMPOS SIN EL TIPO
             //tab_hechos="";
             nodo_arbol aux=lista_jerarquia.get(i);
             if(aux.dimencion_activa)
             {
               tablas_aux=aux.nombre_nodo;
                      if(aux.estado)
                      {
                           if(tablas_join.equals(""))
                           {
                               tablas_join=aux.nombre_nodo;
                           }
                           else
                           {
                               tablas_join+=","+aux.nombre_nodo;
                           }
                           for(int x=0;x<aux.campos.size();x++){///////////////recorrer los campos de la tabla
                               String []a=(String [])aux.campos.get(x);


                               if(a[0].equals("PK")) /////////comprueba si el campo es llave primaria
                               {
                                   if(!pk.equals(""))
                                   {
                                       //pk+=","+aux.nombre_nodo+"_"+a[1];
                                       //campos_aux+=","+aux.nombre_nodo+"_"+a[1];
                                   }
                                   else
                                   {
                                       //pk=aux.nombre_nodo+"_"+a[1];
                                       //campos_aux=aux.nombre_nodo+"_"+a[1];
                                   }

                                   //cad+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";
                                   campos+=aux.nombre_nodo+"_"+a[1]+" "+a[2];
                                   campos_sin+=aux.nombre_nodo+"_"+a[1];

                                   //tab_hechos+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+" NOT NULL ,\n";
                               }

                               if(a[3].equals("1"))////////////el campo esta seleccionado y se agrega al script
                               {
                                   //cad+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";
                                   campos+=aux.nombre_nodo+"_"+a[1]+" "+a[2]+",";
                                   campos_sin+=aux.nombre_nodo+"_"+a[1]+",";
                               }

                           }
                       }


                       for(int j=0;j<aux.lista_hijos.size()-1;j++)////////////recorrer las tablas que componen la dimension
                       {
                           nodo_arbol aux2=aux.lista_hijos.get(j);
                           if(aux2.estado)
                           {
                               if(tablas_join.equals(""))
                               {
                                   tablas_join=aux.nombre_nodo;
                               }
                               else
                               {
                                   tablas_join+=","+aux.nombre_nodo;
                               }
                               pk="";

                               //tab_hechos="";

                           for(int z=0;z<aux2.campos.size();z++){/////////////recorrer los campos de la tabla
                               String []a=(String [])aux2.campos.get(z);

                               if(a[0].equals("PK"))/////////comprueba si el campo es llave primaria
                               {
                                   if(!pk.equals(""))
                                   {
                                       pk+=","+aux2.nombre_nodo+"_"+a[1];
                                       //campos_aux+=","+aux2.nombre_nodo+"_"+a[1];
                                   }
                                   else
                                   {
                                       pk=aux2.nombre_nodo+"_"+a[1];
                                       //campos_aux=aux2.nombre_nodo+"_"+a[1];
                                   }

                                   //cad+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";
                                   campos+=aux2.nombre_nodo+"_"+a[1]+" "+a[2]+",";
                                   campos_sin+=aux2.nombre_nodo+"_"+a[1]+",";
                                   //tab_hechos+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+" NOT NULL ,\n";
                               }

                               if(a[3].equals("1")) ///////////////////////////el campo esta seleccionado y se agrega al script
                               {
                                   //cad+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+" NULL,\n";
                                   campos+=aux2.nombre_nodo+"_"+a[1]+" "+a[2]+",";
                                   campos_sin+=aux2.nombre_nodo+"_"+a[1]+",";
                               }


                           }
                           }

                       }


                if(tablas.equals(""))
                    tablas+=tablas_aux;
               else
                   tablas+=","+tablas_aux;

                cad_script+="SELECT * FROM DBLINK("+linkeado+"\n 'SELECT "+campos_sin+" FROM "+tablas+" WHERE <condiciones>) AS T("+campos+");\n\n";

             }
             //tab_hechos_aux+=tab_hechos;

         }

         ///////////////LLENADO de la tabla de hechos/////////////////////////
         
       

        cadena_tabla_hechos+="INSERT INTO FROM( \n";
        cadena_tabla_hechos+="SELECT * FROM "+tablas_join+" WHERE <CONDICIONES>";
        cadena_tabla_hechos+=")AS NUEVA)";
        cad_script+="\n \n \n"+cadena_tabla_hechos;
       
     
        
        return cad_script;
    }

    public String generar_script_datos2()
     {
    
        String bd_actual=this.accPrincipal.base_datos;
        String user=this.accPrincipal.user;
        String password=this.accPrincipal.password;
        String linkeado="'dbname="+bd_actual+" user="+user+" password="+password+"',";


         String cad_script="CREATE EXTENSION DBLINK;\n";/////////////cadena con el script
         String tablas=""; //CADENA CON TABLAS EN EL JOIN
         String tablas_aux="";
        

         //String campos_aux="";
         String tab_hechos="";////////////cadena con los campos que se agregaran a la tabla de hechos de cada dimension, la llave primaria
         String tab_hechos_aux="";////////////cadena con la union de los distintos campos que se agregaran a la tabla de hechos, la union del varios tab_hechos
         String pktab_hechos="";/////////////cadena con la llave primaria de la tabla de hechos
         String pktab_hechos_contipo="";
         //String fktab_hechos="";/////////////cadena con las llaves foraneas de la tabla de hechos

         //cad="\nDROP DATABASE "+this.accPrincipal.getNombreBD()+"_estrella"+";\n\n";

         //cad+="\nCREATE DATABASE "+this.accPrincipal.getNombreBD()+"_estrella"+";\n\n";

         /////////ejecutar el script sin especificar una base de datos
         //this.accPrincipal.ejecutarScriptBD(cad_script,"");

         //cad_script="";
         accPrincipal.progresando(10);
         for(int i=0;i<lista_jerarquia.size();i++)////////////recorrer las dimensiones
         {
            String pk="";/////////cadena con la llave primaria de cada dimension
            String campos=""; //CADENA CON CAMPOS Y TIPO DEL CAMPO EN LA CONSULTA DEL JOIN
            //String campos_aux="";
            String campos_sin=""; //CADENA CON CAMPOS SIN EL TIPO
             tab_hechos="";
             nodo_arbol aux=lista_jerarquia.get(i);
             if(aux.nombre_nodo.equals("dimension_tiempo"))
             {
                String cfecha = String.valueOf(jList6.getSelectedValue());
                String ftabla = String.valueOf(jComboBox2.getSelectedItem());
                cad_script+= "INSERT INTO dimension_tiempo\nSELECT T.* \n"+
                "FROM DBLINK("+linkeado+"\n"+ 
                "E'SELECT DISTINCT EXTRACT(YEAR FROM "+cfecha+")*10000+EXTRACT(MONTH FROM "+cfecha+")*100+EXTRACT(DAY FROM "+cfecha+") AS dimension_tiempo_id_tiempo,\n";
                if(jCheckBox1.isSelected())
                    cad_script+="EXTRACT(YEAR FROM " + cfecha +") AS dimension_tiempo_anio,\n";
                if(jCheckBox2.isSelected())
                    cad_script+="CASE\n"+
                    "\tWHEN  EXTRACT(MONTH FROM "+cfecha+") < 6 THEN  \\'1er. semestre\\'\n"+
                    "\tELSE \\'2do. semestre\\'\n"+
                    "END AS dimension_tiempo_semestre,\n";
                if(jCheckBox3.isSelected())
                    cad_script+="CASE \n"+
                    "\tWHEN EXTRACT(MONTH FROM "+cfecha+") <= 3 THEN \\'1er. trimestre\\'\n"+
                    "\tWHEN EXTRACT(MONTH FROM "+cfecha+") >= 4 AND EXTRACT(MONTH FROM "+cfecha+") <= 6 THEN \\'2do. trimestre\\'\n"+
                    "\tWHEN EXTRACT(MONTH FROM "+cfecha+") >= 7 AND EXTRACT(MONTH FROM "+cfecha+") <= 9 THEN \\'3er. trimestre\\'\n"+
                    "\tELSE \\'4to. trimestre\\'\n"+
                    "END AS dimension_tiempo_trimestre,\n";
                if(jCheckBox4.isSelected())
                    cad_script+="TO_CHAR("+cfecha+", \\'Month\\') AS dimension_tiempo_mes,\n";
                if(jCheckBox5.isSelected())
                    cad_script+="EXTRACT(DAY FROM "+cfecha+") AS dimension_tiempo_dia\n";
                cad_script+="FROM "+ftabla+" ORDER BY dimension_tiempo_id_tiempo ASC')\n"+
                "AS T(dimension_tiempo_id_tiempo integer";
                if(jCheckBox1.isSelected())
                    cad_script+=", dimension_tiempo_anio integer\n";
                if(jCheckBox2.isSelected())
                    cad_script+=", dimension_tiempo_semestre character varying(30)\n";
                if(jCheckBox3.isSelected())
                    cad_script+=", dimension_tiempo_trimestre  character varying(30)\n";
                if(jCheckBox4.isSelected())
                    cad_script+=", dimension_tiempo_mes  character varying(30)\n";
                if(jCheckBox5.isSelected())
                    cad_script+=", dimension_tiempo_dia integer\n";
                cad_script+=");\n\n";
             }
             else
             {
             if(aux.dimencion_activa)
             {
               tablas_aux="";
               cad_script+="INSERT INTO "+aux.nombre_nodo+"\n";

                           if(aux.estado)
                           {
                                if(!tablas_aux.equals(""))
                                    tablas_aux=" NATURAL JOIN "+aux.nombre_nodo;
                                else
                                    tablas_aux=aux.nombre_nodo;

                           for(int x=0;x<aux.campos.size();x++){///////////////recorrer los campos de la tabla
                               String []a=(String [])aux.campos.get(x);


                               if(a[0].equals("PK")) /////////comprueba si el campo es llave primaria
                               {
                                   if(!pk.equals(""))
                                   {
                                       pk+=","+aux.nombre_nodo+"_"+a[1];
                                       //campos_aux+=","+aux.nombre_nodo+"_"+a[1];
                                   }
                                   else
                                   {
                                       pk=aux.nombre_nodo+"_"+a[1];
                                       //campos_aux=aux.nombre_nodo+"_"+a[1];
                                   }

                                   //cad+="\t"+aux.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";
                                   if(campos.equals(""))
                                        campos+=aux.nombre_nodo+"."+a[1]+" "+a[2];
                                   else
                                       campos+=","+aux.nombre_nodo+"."+a[1]+" "+a[2];

                                   if(campos_sin.equals(""))
                                        campos_sin+=aux.nombre_nodo+"."+a[1];
                                   else
                                       campos_sin+=","+aux.nombre_nodo+"."+a[1];
                                   if(tab_hechos.equals(""))
                                        tab_hechos+=aux.nombre_nodo+"_"+a[1]+" "+a[2];
                                   else
                                       tab_hechos+=","+aux.nombre_nodo+"_"+a[1]+" "+a[2];
                               }

                               if(a[3].equals("1"))////////////el campo esta seleccionado y se agrega al script
                               {

                                   if(campos.equals(""))
                                        campos+=aux.nombre_nodo+"."+a[1]+" "+a[2];
                                        
                                   else
                                       campos+=","+aux.nombre_nodo+"."+a[1]+" "+a[2];

                                   if(campos_sin.equals(""))
                                        campos_sin+=aux.nombre_nodo+"."+a[1];
                                   else
                                       campos_sin+=","+aux.nombre_nodo+"."+a[1];
                               }

                           }
                       }


                       for(int j=0;j<aux.lista_hijos.size()-1;j++)////////////recorrer las tablas que componen la dimension
                       {
                           nodo_arbol aux2=aux.lista_hijos.get(j);
                           if(aux2.estado){
                               if(!tablas_aux.equals(""))
                                    tablas_aux+=" NATURAL JOIN "+aux2.nombre_nodo;
                               else
                                   tablas_aux+=aux2.nombre_nodo;
                               pk="";

                               tab_hechos="";

                           for(int z=0;z<aux2.campos.size();z++){/////////////recorrer los campos de la tabla
                               String []a=(String [])aux2.campos.get(z);

                               if(a[0].equals("PK"))/////////comprueba si el campo es llave primaria
                               {
                                   if(!pk.equals(""))
                                   {
                                       pk+=","+aux2.nombre_nodo+"_"+a[1];
                                       //campos_aux+=","+aux2.nombre_nodo+"_"+a[1];
                                   }
                                   else
                                   {
                                       pk=aux2.nombre_nodo+"_"+a[1];
                                       //campos_aux=aux2.nombre_nodo+"_"+a[1];
                                   }

                                   //cad+="\t"+aux2.nombre_nodo+"_"+a[1]+" "+a[2]+",\n";
                                   if(campos.equals(""))
                                        campos+=aux2.nombre_nodo+"."+a[1]+" "+a[2];
                                   else
                                       campos+=","+aux2.nombre_nodo+"."+a[1]+" "+a[2];

                                   if(campos_sin.equals(""))
                                        campos_sin+=aux2.nombre_nodo+"."+a[1];
                                   else
                                       campos_sin+=","+aux2.nombre_nodo+"."+a[1];

                                   if(tab_hechos.equals(""))
                                        tab_hechos+=aux2.nombre_nodo+"_"+a[1]+" "+a[2];
                                   else
                                       tab_hechos+=","+aux2.nombre_nodo+"_"+a[1]+" "+a[2];
                                  
                               }

                               if(a[3].equals("1")) ///////////////////////////el campo esta seleccionado y se agrega al script
                               {
                                  
                                   if(campos.equals(""))
                                        campos+=aux2.nombre_nodo+"."+a[1]+" "+a[2];
                                   else
                                       campos+=","+aux2.nombre_nodo+"."+a[1]+" "+a[2];

                                   if(campos_sin.equals(""))
                                        campos_sin+=aux2.nombre_nodo+"."+a[1];
                                   else
                                       campos_sin+=","+aux2.nombre_nodo+"."+a[1];
                               }


                           }
                           }

                       }


               if(pktab_hechos.equals(""))
                    pktab_hechos+=pk;
               else
                    pktab_hechos+=","+pk;


                    tablas=tablas_aux;


                cad_script+="SELECT * FROM DBLINK("+linkeado+"\n 'SELECT "+campos_sin+" FROM "+tablas+"')  AS T("+campos.replace(".", "_")+");\n\n";

             }
             }
             tab_hechos_aux+=tab_hechos;

         }
         accPrincipal.progresando(60);
         nodo_arbol tabla_hechos=this.get_metricas();

         String aux_th_sin="";
         String aux_th="";

        //cad+=tab_hechos_aux;

        for(int z=0;z<tabla_hechos.campos.size();z++){
           String []a=(String [])tabla_hechos.campos.get(z);

           if(!aux_th_sin.equals(""))
                aux_th_sin+=","+tabla_hechos.nombre_nodo+"."+a[1];
           else
               aux_th_sin+=tabla_hechos.nombre_nodo+"."+a[1];

           if(!aux_th.equals(""))
                aux_th=","+tabla_hechos.nombre_nodo+"_"+a[1]+" "+a[2]+" NULL";
           else
               aux_th=tabla_hechos.nombre_nodo+"_"+a[1]+" "+a[2]+" NULL";

       }
        accPrincipal.progresando(70);
    return cad_script;
    }
    public String seleccionar_ubicacion( JTextField txt, int tipo, String titulo ) {
        manejoProyecto = new JFileChooser();
        
        manejoProyecto.setFileSelectionMode( tipo );
        manejoProyecto.setDialogTitle(titulo);
        int seleccion = manejoProyecto.showOpenDialog( jdProyecto );
        
        if( seleccion == JFileChooser.APPROVE_OPTION ){
            File f = manejoProyecto.getSelectedFile();
            System.out.println( f.getAbsolutePath() );
            try{
            	//String nombre = f.getName();
            	String path = f.getAbsolutePath();
                txt.setText(path);
            }
            catch( Exception e){}
        }
        return "";
    }
    JFileChooser manejoProyecto;
    
    String password()
    {
        String password = "";
        for (char a : txtPassword1.getPassword())
            password += a;
        
        System.out.println("----**"+password);
        return password;
    }
    
    public ArrayList get_condiciones(String tabla){
       
        
        boolean entro=false;
        ArrayList<String> tmp=new ArrayList<String>();
        try {
            
          ResultSet rs = accPrincipal.get_relaciones(tabla); 
          while(rs.next()){
              
              String tbl_sigiente=rs.getString("tabla_foranea");
              String definicion=rs.getString("definicion");
                definicion=definicion.replace("FOREIGN KEY ",tabla);
                definicion=definicion.replace("REFERENCES","=");
                definicion=definicion.replace(")","");
                definicion=definicion.replace("(",".");
                definicion=definicion.replace(" ","");
                
                String [] partes= definicion.split("=");           
                
               String []seccion1=partes[0].split(",");
               String []seccion2=partes[1].split(",");
                
               if(seccion1.length>1){
                   definicion=seccion1[0]+"="+seccion2[0];
                   for(int i=1;i<seccion1.length;i++){
                      definicion+=" and "+tabla+"."+seccion1[i]+"="+tbl_sigiente+"."+seccion2[i];
                   }
                   
               }

          //      System.out.println(definicion);
              
              ArrayList<String> x= get_condiciones(tbl_sigiente);
              
              if(x.size()>0){
               for(int i=0;i<x.size();i++){
                  String tempp=definicion+" And "+x.get(i);
                  tmp.add(tempp);
              }
              }
              else{
                  tmp.add(definicion);
                  
              }
              
              entro=true;
          }
         
             return tmp; 
        } catch (SQLException ex) {
            Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public void run(){
        jdProyecto.setVisible(false);
        this.setEnabled(false);
        lblMensajeProgreso.setText(getDescripcion());
        jpbProgreso.setValue(0);
        jdProgreso.setSize(300,100);
        jdProgreso.setLocationRelativeTo(null);
        jdProgreso.setAlwaysOnTop(true);
        jdProgreso.setVisible(true);
        
        switch( getOperacion() ){
            case CREAR_PROYECTO: crear_proyecto(); break;
            case GENERAR_SCRIPT_ESTRELLA: jTextArea1.setText(generar_script_estrella()); 
                break;
            case EJECUTAR_SCRIPT: 
                this.accPrincipal.ejecutarScriptBD(jTextArea1.getText(),this.accPrincipal.getNombreBD()+"_estrella"); 
                break;
            case GENERAR_SCRIPT_DATOS:
                jTextArea2.setText(generar_script_datos2());
                jTextArea2.append(query_full_tabla_hecho());
                break;
            case EJECUTAR_SCRIPT_DATOS:
                this.accPrincipal.ejecutarScriptBD(jTextArea2.getText(),this.accPrincipal.getNombreBD()+"_estrella"); 
                break;
        }
        jdProgreso.setVisible(false);
        this.setEnabled(true);
    }

    public String getDescripcion() {
        return descripcion;
    }

    public void setDescripcion(String descripcion) {
        this.descripcion = descripcion;
    }

    public byte getOperacion() {
        return operacion;
    }

    public void setOperacion(byte operacion) {
        this.operacion = operacion;
    }
    
    public void crear_proyecto(){
        propiedades.setnProyecto(txtNProyecto.getText());
        accPrincipal.crearProyecto(txtUsuario1.getText(), password(), 
                txtServidor.getText(), txtPuerto.getText(), txtNombreBD1.getText(), 
                txtUProyecto.getText(), txtUBackUP.getText(), propiedades );
        this.setTitle( txtNProyecto.getText() );
        jdProyecto.setVisible(false);
        propiedades.setnProyecto(txtNProyecto.getText());
    }
    
    Propiedades propiedades;
    String descripcion;
    byte operacion;
    public final static byte CREAR_PROYECTO = 0;
    public final static byte GENERAR_SCRIPT_ESTRELLA = 1;
    public final static byte EJECUTAR_SCRIPT = 2;
    public final static byte GENERAR_SCRIPT_DATOS = 3;
    public final static byte EJECUTAR_SCRIPT_DATOS = 4;
}
